﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace vorkos_dev_snake
{
    [Serializable]
    public class Field
    {
        private  Coordinate[] field;
        private  List<Coordinate> food;

        public Field()
        {
            this.food = new List<Coordinate>();
            Coordinate dimentions = GameLogic.Instance.UI.GetDimmentions();
            this.field = new Coordinate[dimentions.Y * dimentions.X];
            int fieldFence = (dimentions.Y - 1) * 2 + (dimentions.X - 1) * 2;
            for (int i = 0; i < dimentions.Y - 1; i++)
            {
                for (int j = 0; j < dimentions.X - 1; j++)
                {
                    if (j == 0 || j == (dimentions.X - 2) || i == 0 || i == (dimentions.Y - 2))
                    {
                        this.field[i * dimentions.X + j].X = (ushort)j;
                        this.field[i * dimentions.X + j].Y = (ushort)i;
                    }
                }
            }
            GameLogic.Instance.UI.DrawField(this);
        }
        public Boolean AddFoodOnField(Coordinate newFood)
        {
            this.food.Add(newFood);
            GameLogic.Instance.UI.DrawFood(this);
            return true;
        }
        public Boolean RemoveFood(Coordinate eatenFood)
        {
            if (this.food!=null) food.Remove(eatenFood);
            return true;
        }
        public List<Coordinate> GetFood()
        {
            return this.food;
        }

        public Coordinate[] GetField()
        {
            return this.field;
        }
    }
}
